﻿//  -------------------- iSharePoint -------------------- //
// 
//  Company:	IT Complex, LLC
//  Project:	Smart.Common
//  File name:	WebEntityFacade.cs
//  Developer:	Solomatov Igor
//  Created:	15.04.2012
// 
//  -------------------- iSharePoint -------------------- //

using Microsoft.SharePoint;

namespace Smart.Common.Entities
{
	/// <summary>
	/// SharePoint Entity facade
	/// </summary>
	public class WebEntityFacade<TEntityType> : EntityFacade<TEntityType>, IWebEntityFacade<TEntityType> where TEntityType : Entity
	{
		public WebEntityFacade(string name, FacadeMappingInfo mappingInfo, IListService<TEntityType> service)
			: base(name, mappingInfo, service)
		{
		}

		/// <summary>
		/// List root folder
		/// </summary>
		public SPFolder Folder
		{
			get { return ((WebListService<TEntityType>)Service).List.RootFolder; }
		}

		public override IQueryBuilder<IEntityFacadeQueryExecutor<TEntityType>> Query
		{
			get
			{
				var query = new CamlQueryBuilder<IEntityFacadeQueryExecutor<TEntityType>>(Service.Meta, new EntityFacadeQueryExecutor<TEntityType>(this));

				query.Executor.Query = query;

				return query;
			}
		}
	}
}